package com.ruoyi.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.IdVo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.RolePermVo;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.user.domain.TbPerm;
import com.ruoyi.user.domain.TbRole;
import com.ruoyi.user.domain.TbRolePerm;
import com.ruoyi.user.service.TbRolePermService;
import com.ruoyi.user.mapper.TbRolePermMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbRolePermServiceImpl extends ServiceImpl<TbRolePermMapper, TbRolePerm>
        implements TbRolePermService {

    @Autowired
    private TbRolePermMapper tbRolePermMapper;

    @Override
    public R addRolePerm(RolePermVo rolePermVo) {

        TbRolePerm tbRolePerm = new TbRolePerm();
        BeanUtils.copyProperties(rolePermVo, tbRolePerm);
        tbRolePerm.setUpdateBy("admin");
        tbRolePerm.setCreateBy("admin");
        int insert = tbRolePermMapper.insert(tbRolePerm);

        return insert > 0 ? R.ok("添加成功") : R.fail("添加失败");
    }

    @Override
    public R deleteRolePerm(IdVo idVo) {

        int delete = tbRolePermMapper.deleteById(idVo.getId());
        return delete > 0 ? R.ok("删除成功") : R.fail("删除失败");
    }

    @Override
    public AjaxResult selectRolePerm() {

        List<TbRolePerm> tbRolePerms = tbRolePermMapper.selectList(null);
        return AjaxResult.success("查询可能为空", tbRolePerms);
    }

    @Override
    public R updateRolePerm(RolePermVo rolePermVo) {

        TbRolePerm tbRolePerm = new TbRolePerm();
        BeanUtils.copyProperties(rolePermVo, tbRolePerm);
        tbRolePerm.setUpdateBy("admin");
        tbRolePerm.setUpdateTime(null);
        int update = tbRolePermMapper.updateById(tbRolePerm);
        return update > 0 ? R.ok("修改成功") : R.fail("修改失败");

    }

}




